***this file merges in the necessary data to create a replication file from 2001-2018 using alternative vdem and other measures proxying Finkel's choices.

***Set directory to the Replicationgovernance\finkelextension folder

cd "XXX\ReplicationGovernance\Finkelextension"

*Bring in vdem data as a base.  ***NOTE THAT THIS DATA IS NOT IN THE REPLICATION PACKAGE DUE TO ITS LARGE SIZE.  You MUST download the V-Dem v9 w/covariates dataset if you wish to execute this analysis from the core data merge and clean***

use "vdem v9\V-Dem-CY-Full+Others-v9.dta"

*drop data there's no chance of using

drop if year<1950

*merge in USAID and US government aid data that forms the core of Finkel et al for a different period with disbursement data.

merge 1:m country_text_id year using "USAIDdata20022018.dta", generate(_mergeusaid)

*using file cases that did not match are very small countries not rated bytab vdem.  Drop them.

drop if _mergeusaid==2

*merge in ODA data

merge 1:m country_text_id year using "oda20002018.dta", generate(_mergeoda)

*drop small countries that have no vdem code and vdem non-existent data for south sudan before its independence and some palestine data that vdem does not match for a few years.

drop if _mergeoda==2

*merge in spread out regional aid data variables

merge m:1 year using "USAID20012018regionsplit.dta", generate(_mergeregion)

***generate regional figures for all countries that are in the data from 2001-2018 using info from other file and region composition

tab country_text_id if year>2000

*country by country create regional DG and non-dg figures

gen regionaldg=.
gen regionalnondg=.

*all country figures gathered by searching through the region definitions created in previous generateregionaldatastub.do

*AFG in 1005, 1006, 1029, 1030
replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1029dgsplit+_region1030dgsplit if country_text_id=="AFG"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1029nondgsplit+_region1030nondgsplit if country_text_id=="AFG"

*AGO in 1013, 1033,

replace regionaldg=_region1013dgsplit+_region1033dgsplit if country_text_id=="AGO"
replace regionalnondg=_region1013nondgsplit+_region1033nondgsplit if country_text_id=="AGO"

*ALB in 1009, 1015,  1018

replace regionaldg=_region1009dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="ALB"
replace regionalnondg=_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="ALB"

*ARE in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="ARE"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="ARE"
 
*ARG in  1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="ARG"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="ARG"

*ARM in 1005, 1006, 1015, 1019

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1015dgsplit+_region1019dgsplit if country_text_id=="ARM"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1015nondgsplit+_region1019nondgsplit if country_text_id=="ARM"

*AUS in 1012, 1027

replace regionaldg=_region1012dgsplit+_region1027dgsplit if country_text_id=="AUS"
replace regionalnondg=_region1012nondgsplit+_region1027nondgsplit if country_text_id=="AUS"

*AUT in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="AUT"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="AUT"

*AZE in 1005, 1006, 1015, 1019

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1015dgsplit+_region1019dgsplit if country_text_id=="AZE"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1015nondgsplit+_region1019nondgsplit if country_text_id=="AZE"

*BDI in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="BDI"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="BDI"

*BEL in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="BEL"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="BEL"

*BEN in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="BEN"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="BEN"

*BFA in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="BFA"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="BFA"

*BGD in 1005, 1006, 1029, 1030 

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1029dgsplit+_region1030dgsplit if country_text_id=="BGD"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1029nondgsplit+_region1030nondgsplit if country_text_id=="BGD"

*BGR in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="BGR"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="BGR"

*BHR in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="BHR"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="BHR"

*BIH in 1009, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="BIH"
replace regionalnondg=_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="BIH"

*BLR in 1015, 1018, 1019

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1019dgsplit if country_text_id=="BLR"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1019nondgsplit if country_text_id=="BLR"

*BOL in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="BOL"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="BOL"

*BRA in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="BRA"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="BRA"

*BRB in 1008, 1010, 1021

replace regionaldg=_region1008dgsplit+_region1010dgsplit+_region1021dgsplit if country_text_id=="BRB"
replace regionalnondg=_region1008nondgsplit+_region1010nondgsplit+_region1021nondgsplit if country_text_id=="BRB"

*BTN in 1005, 1006, 1029, 1030

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1029dgsplit+_region1030dgsplit if country_text_id=="BTN"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1029nondgsplit+_region1030nondgsplit if country_text_id=="BTN"

*BWA in 1017, 1028, 1033

replace regionaldg=_region1017dgsplit+_region1028dgsplit+_region1033dgsplit if country_text_id=="BWA"
replace regionalnondg=_region1017nondgsplit+_region1028nondgsplit+_region1033nondgsplit if country_text_id=="BWA"

*CAF in 1017, 1033

replace regionaldg=_region1017dgsplit+_region1033dgsplit if country_text_id=="CAF"
replace regionalnondg=_region1017nondgsplit+_region1033nondgsplit if country_text_id=="CAF"

*CAN in 1024, 1025

replace regionaldg=_region1024dgsplit+_region1025dgsplit if country_text_id=="CAN"
replace regionalnondg=_region1024nondgsplit+_region1025nondgsplit if country_text_id=="CAN"

*CHE in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="CHE"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="CHE"

*CHL in  1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="CHL"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="CHL"

*CHN in 1005, 1006, 1012, 1016

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1016dgsplit if country_text_id=="CHN"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1016nondgsplit if country_text_id=="CHN"

*CIV in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="CIV"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="CIV"

*CMR in 1013, 1033

replace regionaldg=_region1013dgsplit+_region1033dgsplit if country_text_id=="CMR"
replace regionalnondg=_region1013nondgsplit+_region1033nondgsplit if country_text_id=="CMR"

*COD in 1013, 1033

replace regionaldg=_region1013dgsplit+_region1033dgsplit if country_text_id=="COD"
replace regionalnondg=_region1013nondgsplit+_region1033nondgsplit if country_text_id=="COD"

*COG in 1013, 1033

replace regionaldg=_region1013dgsplit+_region1033dgsplit if country_text_id=="COG"
replace regionalnondg=_region1013nondgsplit+_region1033nondgsplit if country_text_id=="COG"

*COL in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="COL"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="COL"

*COM in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="COM"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="COM"

*CPV in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="CPV"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="CPV"

*CRI in 1007, 1008, 1020, 1021, 1025

replace regionaldg=_region1007dgsplit+_region1008dgsplit+_region1020dgsplit+_region1021dgsplit+_region1025dgsplit if country_text_id=="CRI"
replace regionalnondg=_region1007nondgsplit+_region1008nondgsplit+_region1020nondgsplit+_region1021nondgsplit+_region1025nondgsplit if country_text_id=="CRI"

*CUB in 1008, 1010, 1021

replace regionaldg=_region1008dgsplit+_region1010dgsplit+_region1021dgsplit if country_text_id=="CUB"
replace regionalnondg=_region1008nondgsplit+_region1010nondgsplit+_region1021nondgsplit if country_text_id=="CUB"

*CYP in 1009, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="CYP"
replace regionalnondg=_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="CYP"

*CZE in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="CZE"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="CZE"

*DEU in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="DEU"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="DEU"

*DJI in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="DJI"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="DJI"

*DNK in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="DNK"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="DNK"

*DOM in 1008, 1010, 1021

replace regionaldg=_region1008dgsplit+_region1010dgsplit+_region1021dgsplit if country_text_id=="DOM"
replace regionalnondg=_region1008nondgsplit+_region1010nondgsplit+_region1021nondgsplit if country_text_id=="DOM"

*DZA in 1005, 1023, 1026

replace regionaldg=_region1005dgsplit+_region1023dgsplit+_region1026dgsplit if country_text_id=="DZA"
replace regionalnondg=_region1005nondgsplit+_region1023nondgsplit+_region1026nondgsplit if country_text_id=="DZA"

*ECU in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="ECU"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="ECU"

*EGY in 1005, 1006, 1022, 1023, 1026

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit+_region1026dgsplit if country_text_id=="EGY"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit+_region1026nondgsplit if country_text_id=="EGY"

*ERI in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="ERI"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="ERI"

*ESP in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="ESP"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="ESP"

*EST in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="EST"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="EST"

*ETH in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="ETH"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="ETH"

*FIN in 1009, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="FIN"
replace regionalnondg=_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="FIN"

*FJI in 1012, 1027

replace regionaldg=_region1012dgsplit+_region1027dgsplit if country_text_id=="FJI"
replace regionalnondg=_region1012nondgsplit+_region1027nondgsplit if country_text_id=="FJI"

*FRA in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="FRA"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="FRA"

*GAB in 1013, 1033

replace regionaldg=_region1013dgsplit+_region1033dgsplit if country_text_id=="GAB"
replace regionalnondg=_region1013nondgsplit+_region1033nondgsplit if country_text_id=="GAB"

*GBR in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="GBR"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="GBR"

*GEO in 1005, 1006, 1015, 1019

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1015dgsplit+_region1019dgsplit if country_text_id=="GEO"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1015nondgsplit+_region1019nondgsplit if country_text_id=="GEO"

*GHA in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="GHA"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="GHA"

*GIN in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="GIN"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="GIN"

*GMB in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="GMB"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="GMB"

*GNB in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="GNB"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="GNB"

*GNQ in 1013, 1033

replace regionaldg=_region1013dgsplit+_region1033dgsplit if country_text_id=="GNQ"
replace regionalnondg=_region1013nondgsplit+_region1033nondgsplit if country_text_id=="GNQ"

*GRC in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="GRC"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="GRC"

*GTM in 1007, 1008, 1020, 1021, 1025

replace regionaldg=_region1007dgsplit+_region1008dgsplit+_region1020dgsplit+_region1021dgsplit+_region1025dgsplit if country_text_id=="GTM"
replace regionalnondg=_region1007nondgsplit+_region1008nondgsplit+_region1020nondgsplit+_region1021nondgsplit+_region1025nondgsplit if country_text_id=="GTM"

*GUY in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="GUY"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="GUY"

*HKG in 1005, 1006, 1012, 1016

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1016dgsplit if country_text_id=="HKG"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1016nondgsplit if country_text_id=="HKG"

*HND in 1007, 1008, 1020, 1021, 1025

replace regionaldg=_region1007dgsplit+_region1008dgsplit+_region1020dgsplit+_region1021dgsplit+_region1025dgsplit if country_text_id=="HND"
replace regionalnondg=_region1007nondgsplit+_region1008nondgsplit+_region1020nondgsplit+_region1021nondgsplit+_region1025nondgsplit if country_text_id=="HND"

*HRV in 1009, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="HRV"
replace regionalnondg=_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="HRV"

*HTI in 1008, 1010, 1021

replace regionaldg=_region1008dgsplit+_region1010dgsplit+_region1021dgsplit if country_text_id=="HTI"
replace regionalnondg=_region1008nondgsplit+_region1010nondgsplit+_region1021nondgsplit if country_text_id=="HTI"

*HUN in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="HUN"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="HUN"

*IDN in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="IDN"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="IDN"

*IND in 1005, 1006, 1029, 1030 

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1029dgsplit+_region1030dgsplit if country_text_id=="IND"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1029nondgsplit+_region1030nondgsplit if country_text_id=="IND"

*IRL in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="IRL"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="IRL"

*IRN in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="IRN"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="IRN"

*IRQ in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="IRQ"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="IRQ"

*ISL in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="ISL"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="ISL"

*ISR in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="ISR"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="ISR"

*ITA in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="ITA"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="ITA"

*JAM in 1008, 1010, 1021

replace regionaldg=_region1008dgsplit+_region1010dgsplit+_region1021dgsplit if country_text_id=="JAM"
replace regionalnondg=_region1008nondgsplit+_region1010nondgsplit+_region1021nondgsplit if country_text_id=="JAM"

*JOR in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="JOR"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="JOR"

*JPN in 1005, 1006, 1012, 1016

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1016dgsplit if country_text_id=="JPN"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1016nondgsplit if country_text_id=="JPN"

*KAZ in 1005, 1006, 1030

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1030dgsplit if country_text_id=="KAZ"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1030nondgsplit if country_text_id=="KAZ"

*KEN in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="KEN"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="KEN"

*KGZ in 1005, 1006, 1030

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1030dgsplit if country_text_id=="KGZ"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1030nondgsplit if country_text_id=="KGZ"

*KHM in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="KHM"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="KHM"

*KOR in 1005, 1006, 1012, 1016

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1016dgsplit if country_text_id=="KOR"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1016nondgsplit if country_text_id=="KOR"

*KWT in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="KWT"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="KWT"

*LAO in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="LAO"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="LAO"

*LBN in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="LBN"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="LBN"

*LBR in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="LBR"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="LBR"

*LBY in 1005, 1023, 1026

replace regionaldg=_region1005dgsplit+_region1023dgsplit+_region1026dgsplit if country_text_id=="LBY"
replace regionalnondg=_region1005nondgsplit+_region1023nondgsplit+_region1026nondgsplit if country_text_id=="LBY"

*LKA in 1005, 1006, 1029, 1030 

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1029dgsplit+_region1030dgsplit if country_text_id=="LKA"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1029nondgsplit+_region1030nondgsplit if country_text_id=="LKA"

*LSO in 1017, 1028, 1033

replace regionaldg=_region1017dgsplit+_region1028dgsplit+_region1033dgsplit if country_text_id=="LSO"
replace regionalnondg=_region1017nondgsplit+_region1028nondgsplit+_region1033nondgsplit if country_text_id=="LSO"

*LTU in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="LTU"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="LTU"

*LUX in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="LUX"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="LUX"

*LVA in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="LVA"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="LVA"

*MAR in 1005, 1023, 1026

replace regionaldg=_region1005dgsplit+_region1023dgsplit+_region1026dgsplit if country_text_id=="MAR"
replace regionalnondg=_region1005nondgsplit+_region1023nondgsplit+_region1026nondgsplit if country_text_id=="MAR"

*MDA in 1005, 1006, 1009, 1015 1018, 1019

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1009dgsplit+_region1015dgsplit+_region1018dgsplit+_region1019dgsplit if country_text_id=="MDA"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit+_region1019nondgsplit if country_text_id=="MDA"

*MDG in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="MDG"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="MDG"

*MDV in 1005, 1006, 1029, 1030 

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1029dgsplit+_region1030dgsplit if country_text_id=="MDV"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1029nondgsplit+_region1030nondgsplit if country_text_id=="MDV"

*MEX in 1020, 1021, 1024, 1025

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1024dgsplit+_region1025dgsplit if country_text_id=="MEX"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1024nondgsplit+_region1025nondgsplit if country_text_id=="MEX"

*MKD in 1009, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="MKD"
replace regionalnondg=_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="MKD"

*MLI in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="MLI"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="MLI"

*MLT in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="MLT"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="MLT"

*MMR in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="MMR"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="MMR"

*MNE in 1009, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="MNE"
replace regionalnondg=_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="MNE"

*MNG in 1005, 1006, 1012, 1016

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1016dgsplit if country_text_id=="MNG"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1016nondgsplit if country_text_id=="MNG"

*MOZ in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="MOZ"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="MOZ"

*MRT in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="MRT"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="MRT"

*MUS in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="MUS"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="MUS"

*MWI in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="MWI"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="MWI"

*MYS in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="MYS"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="MYS"

*NAM in 1017, 1028, 1033

replace regionaldg=_region1017dgsplit+_region1028dgsplit+_region1033dgsplit if country_text_id=="NAM"
replace regionalnondg=_region1017nondgsplit+_region1028nondgsplit+_region1033nondgsplit if country_text_id=="NAM"

*NER in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="NER"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="NER"

*NGA in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="NGA"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="NGA"

*NIC in 1007, 1008, 1020, 1021, 1025

replace regionaldg=_region1007dgsplit+_region1008dgsplit+_region1020dgsplit+_region1021dgsplit+_region1025dgsplit if country_text_id=="NIC"
replace regionalnondg=_region1007nondgsplit+_region1008nondgsplit+_region1020nondgsplit+_region1021nondgsplit+_region1025nondgsplit if country_text_id=="NIC"

*NLD in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="NLD"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="NLD"

*NOR in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="NOR"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="NOR"

*NPL in 1005, 1006, 1029, 1030 

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1029dgsplit+_region1030dgsplit if country_text_id=="NPL"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1029nondgsplit+_region1030nondgsplit if country_text_id=="NPL"

*NZL in 1012, 1027

replace regionaldg=_region1012dgsplit+_region1027dgsplit if country_text_id=="NZL"
replace regionalnondg=_region1012nondgsplit+_region1027nondgsplit if country_text_id=="NZL"

*OMN in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="OMN"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="OMN"

*PAK in 1005, 1006, 1029, 1030 

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1029dgsplit+_region1030dgsplit if country_text_id=="PAK"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1029nondgsplit+_region1030nondgsplit if country_text_id=="PAK"

*PAN in 1007, 1008, 1020, 1021, 1025

replace regionaldg=_region1007dgsplit+_region1008dgsplit+_region1020dgsplit+_region1021dgsplit+_region1025dgsplit if country_text_id=="PAN"
replace regionalnondg=_region1007nondgsplit+_region1008nondgsplit+_region1020nondgsplit+_region1021nondgsplit+_region1025nondgsplit if country_text_id=="PAN"

*PER in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="PER"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="PER"

*PHL in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="PHL"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="PHL"

*PNG in 1012, 1027

replace regionaldg=_region1012dgsplit+_region1027dgsplit if country_text_id=="PNG"
replace regionalnondg=_region1012nondgsplit+_region1027nondgsplit if country_text_id=="PNG"

*POL in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="POL"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="POL"

*PRK in 1005, 1006, 1012, 1016

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1016dgsplit if country_text_id=="PRK"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1016nondgsplit if country_text_id=="PRK"

*PRT in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="PRT"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="PRT"

*PRY in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="PRY"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="PRY"

*PSE in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="PSE"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="PSE"

*PSG in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="PSG"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="PSG"

*QAT in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="QAT"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="QAT"

*ROU in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="ROU"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="ROU"

*RUS in 1005, 1006, 1015, 1018, 1019

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1015dgsplit+_region1018dgsplit+_region1019dgsplit if country_text_id=="RUS"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1015nondgsplit+_region1018nondgsplit+_region1019nondgsplit if country_text_id=="RUS"

*RWA in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="RWA"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="RWA"

*SAU in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="SAU"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="SAU"

*SDN in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="SDN"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="SDN"

*SEN in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="SEN"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="SEN"

*SGP in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="SGP"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="SGP"

*SLB in 1012, 1027

replace regionaldg=_region1012dgsplit+_region1027dgsplit if country_text_id=="SLB"
replace regionalnondg=_region1012nondgsplit+_region1027nondgsplit if country_text_id=="SLB"

*SLE in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="SLE"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="SLE"

*SLV in 1007, 1008, 1020, 1021, 1025

replace regionaldg=_region1007dgsplit+_region1008dgsplit+_region1020dgsplit+_region1021dgsplit+_region1025dgsplit if country_text_id=="SLV"
replace regionalnondg=_region1007nondgsplit+_region1008nondgsplit+_region1020nondgsplit+_region1021nondgsplit+_region1025nondgsplit if country_text_id=="SLV"

*No Somaliland

*SOM in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="SOM"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="SOM"

*SRB in 1009, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="SRB"
replace regionalnondg=_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="SRB"

*SSD in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="SSD"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="SSD"

*STP in 1013, 1033

replace regionaldg=_region1013dgsplit+_region1033dgsplit if country_text_id=="STP"
replace regionalnondg=_region1013nondgsplit+_region1033nondgsplit if country_text_id=="STP"

*SUR in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="SUR"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="SUR"

*SVK in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="SVK"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="SVK"

*SVN in 1009, 1014, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1014dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="SVN"
replace regionalnondg=_region1009nondgsplit+_region1014nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="SVN"

*SWE in 1015, 1018, 1036

replace regionaldg=_region1015dgsplit+_region1018dgsplit+_region1036dgsplit if country_text_id=="SWE"
replace regionalnondg=_region1015nondgsplit+_region1018nondgsplit+_region1036nondgsplit if country_text_id=="SWE"

*SWZ in 1017, 1028, 1033

replace regionaldg=_region1017dgsplit+_region1028dgsplit+_region1033dgsplit if country_text_id=="SWZ"
replace regionalnondg=_region1017nondgsplit+_region1028nondgsplit+_region1033nondgsplit if country_text_id=="SWZ"

*SYC in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="SYC"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="SYC"

*SYR in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="SYR"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="SYR"

*TCD in 1013, 1033

replace regionaldg=_region1013dgsplit+_region1033dgsplit if country_text_id=="TCD"
replace regionalnondg=_region1013nondgsplit+_region1033nondgsplit if country_text_id=="TCD"
 
*TGO in 1033, 1034

replace regionaldg=_region1033dgsplit+_region1034dgsplit if country_text_id=="TGO"
replace regionalnondg=_region1033nondgsplit+_region1034nondgsplit if country_text_id=="TGO"

*THA in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="THA"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="THA"

*TJK in 1005, 1006, 1030

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1030dgsplit if country_text_id=="TJK"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1030nondgsplit if country_text_id=="TJK"

*TKM in 1005, 1006, 1030

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1030dgsplit if country_text_id=="TKM"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1030nondgsplit if country_text_id=="TKM"

*TLS in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="TLS"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="TLS"

*TTO in 1008, 1010, 1021

replace regionaldg=_region1008dgsplit+_region1010dgsplit+_region1021dgsplit if country_text_id=="TTO"
replace regionalnondg=_region1008nondgsplit+_region1010nondgsplit+_region1021nondgsplit if country_text_id=="TTO"

*TUN in 1005, 1023, 1026

replace regionaldg=_region1005dgsplit+_region1023dgsplit+_region1026dgsplit if country_text_id=="TUN"
replace regionalnondg=_region1005nondgsplit+_region1023nondgsplit+_region1026nondgsplit if country_text_id=="TUN"

*TUR in 1005, 1006, 1015, 1018, 1019

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1015dgsplit+_region1018dgsplit+_region1019dgsplit if country_text_id=="TUR"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1015nondgsplit+_region1018nondgsplit+_region1019nondgsplit if country_text_id=="TUR"

*TWN in 1005, 1006, 1012, 1016

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1016dgsplit if country_text_id=="TWN"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1016nondgsplit if country_text_id=="TWN"

*TZA in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="TZA"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="TZA"

*UGA in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="UGA"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="UGA"

*UKR in 1005, 1006, 1015, 1019

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1015dgsplit+_region1019dgsplit if country_text_id=="UKR"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1015nondgsplit+_region1019nondgsplit if country_text_id=="UKR"

*URY in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="URY"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="URY"

*USA in 1024, 1025

replace regionaldg=_region1024dgsplit+_region1025dgsplit if country_text_id=="USA"
replace regionalnondg=_region1024nondgsplit+_region1025nondgsplit if country_text_id=="USA"

*UZB in 1005, 1006, 1030

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1030dgsplit if country_text_id=="UZB"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1030nondgsplit if country_text_id=="UZB"

*VEN in 1020, 1021, 1032

replace regionaldg=_region1020dgsplit+_region1021dgsplit+_region1032dgsplit if country_text_id=="VEN"
replace regionalnondg=_region1020nondgsplit+_region1021nondgsplit+_region1032nondgsplit if country_text_id=="VEN"

*VNM in 1005, 1006, 1012, 1031

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1012dgsplit+_region1031dgsplit if country_text_id=="VNM"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1012nondgsplit+_region1031nondgsplit if country_text_id=="VNM"

*VUT in 1012, 1027

replace regionaldg=_region1012dgsplit+_region1027dgsplit if country_text_id=="VUT"
replace regionalnondg=_region1012nondgsplit+_region1027nondgsplit if country_text_id=="VUT"

*XKX (Kosovo) in 1009, 1015, 1018

replace regionaldg=_region1009dgsplit+_region1015dgsplit+_region1018dgsplit if country_text_id=="XKX"
replace regionalnondg=_region1009nondgsplit+_region1015nondgsplit+_region1018nondgsplit if country_text_id=="XKX"

*YEM in 1005, 1006, 1022, 1023

replace regionaldg=_region1005dgsplit+_region1006dgsplit+_region1022dgsplit+_region1023dgsplit if country_text_id=="YEM"
replace regionalnondg=_region1005nondgsplit+_region1006nondgsplit+_region1022nondgsplit+_region1023nondgsplit if country_text_id=="YEM"

*ZAF in 1017, 1028, 1033

replace regionaldg=_region1017dgsplit+_region1028dgsplit+_region1033dgsplit if country_text_id=="ZAF"
replace regionalnondg=_region1017nondgsplit+_region1028nondgsplit+_region1033nondgsplit if country_text_id=="ZAF"

*ZMB in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="ZMB"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="ZMB"

*ZWE in 1011, 1013, 1017, 1033

replace regionaldg=_region1011dgsplit+_region1013dgsplit+_region1017dgsplit+_region1033dgsplit if country_text_id=="ZWE"
replace regionalnondg=_region1011nondgsplit+_region1013nondgsplit+_region1017nondgsplit+_region1033nondgsplit if country_text_id=="ZWE"

*ZZB no zanzibar data

****other variables

*GDP Growth/Capita---in QoG merge here

*generate regional level of democracy to measure diffusion

sort e_regiongeo year
by e_regiongeo year: egen diffusion = mean(v2x_polyarchy) 

*generated military support percent of Finkel's for data, merge in, again drop using file cases that did not match are very small countries not rated by vdem.

merge 1:m year country_text_id using "FPPdata20012018.dta", generate(_mergemilitary)
drop if _mergemilitary==2

*use vdem conflict index v2x_civlib

*state failure variable using v2svstterr (% controlled by government).  Used face validity of case examination of <60

gen statefailure=0
replace statefailure=1 if v2svstterr<60

*static variables

*use ordinal measure from vdem of regime type, sum years as democracy according to vdem categorical classification by Luhrmann, Tannenberg, and Lindberg

gen free=0
replace free=1 if v2x_regime>1
sort country_text_id
by country_text_id: egen yearsfree19812001 = sum(free) if year>1980 & year<2001
by country_text_id: egen yearsfree19812001max = max(yearsfree19812001)

*size country in vdem e_area.  Use variable as largest size after 2001 to make sure it's static

sort country_text_id
by country_text_id: egen static2area = max(e_area) if year>2001

*years of state failure 1971-2001

sort country_text_id
by country_text_id: egen statefailure19712001=sum(statefailure) if year>1970 & year<2002
by country_text_id: egen statefailure19712001max=max(statefailure19712001) 

*QoG merge in variables. Drop unmatched cases, which are almost exclusively small countries not in vdem

merge m:1 country_text_id year using "QoGdata20012018.dta", generate(_mergeQoD)

drop if _mergeQoD==2

*do some minor cleanup work, also change election year variables into constant repeated variables

*light cleanup
*replace non-poorly merged observations (4 semi-country cases) as 0s if they were only in master vdem data---developed and other countries that do not receive DG or non-DG and didn't show up at all in data explorer.

gen explorermissing=0
replace explorermissing=1 if country_text_id=="XKX" | country_text_id=="ZZB" | country_text_id=="SML" | country_text_id=="PSG"

replace USAIDdgconstant2016repeat=0 if USAIDdgconstant2016repeat==. & explorermissing==0
replace USAIDnondgconstant2016repeat=0 if USAIDnondgconstant2016repeat==. & explorermissing==0
replace nonUSAIDconstant2016repeat=0 if nonUSAIDconstant2016repeat==. & explorermissing==0



***********************Repeat observations of electoral variables
xtset country_id year
replace v2elrgstry = L.v2elrgstry if v2elrgstry >= .
replace v2elvotbuy = L.v2elvotbuy if v2elvotbuy >= .
replace v2elirreg = L.v2elirreg if v2elirreg >= .
replace v2elintim = L.v2elintim if v2elintim >= .
replace v2elpeace = L.v2elpeace if v2elpeace >= .
replace v2elmulpar = L.v2elmulpar if v2elmulpar >= .
replace v2elboycot = L.v2elboycot if v2elboycot >= .


*get rid of early unusable years
drop if year<2001

*destring income category of country coded by USAID

destring income_group_id, replace

*replace income group variable where missing with maximum value of income group variable (so when there is another year available, we label correctly)

sort country_text_id
by country_text_id: egen incomegrouprepeat=max(income_group_id)
replace income_group_id=incomegrouprepeat if income_group_id==.

**two countries have no observations in USAID data for obvious reasons so max didn't work for them, handle manually

replace income_group_id=4 if country_text_id=="LUX"
replace income_group_id=4 if country_text_id=="USA"

*generate a couple other country ODA datasets

gen othercountryalloda=alloda-allusoda
gen othercountrydgoda= alldgoda-alldgusoda
gen othercountrynondgoda=othercountryalloda-othercountrydgoda

*observations which are not 2001, which is missing in the oda database, are actually 0 bc they are all developed countries and such except for a couple countries that don't merge well (tab to find out)

gen odamissing=0
replace odamissing=1 if country_text_id=="SML" | country_text_id=="ZZB"

replace othercountryalloda=0 if othercountryalloda==. & year!=2001 & odamissing==0
replace othercountrydgoda=0 if othercountrydgoda==. & year!=2001 & odamissing==0
replace othercountrynondgoda=0 if othercountrynondgoda==. & year!=2001 & odamissing==0

*save this data file, which should be final

save "finkelreplicationdata20012018.dta", replace